<template>
  <div class="wait">
    <!-- <div
      class="wait-robot"
      :class="anAbtn ? 'wait-robot-down' : 'wait-robot-up'"
    ></div> -->
     <div class="wait-robot"></div>
    <div class="wait-word-box">
      <div class="wait-word">正在生成中，请耐心等待哦{{ point }}</div>
    </div>
  </div>
</template>

<script>
import { getInviteInfo, getPaperInfo } from "@/server/api.js";
import { mapGetters } from "vuex";
export default {
  name: "wait",
  components: {},
  data() {
    return {
      point: ".",
      tim: "",
      // anAbtn: false
    };
  },
  created() {
    // if (!this.info.id) {
    //   this.$router.push({
    //     path: "/home"
    //   });
    //   return;
    // }
    this.startTime();
    // this.anaTime(); // animation替换
    this.jumpUrl();
  },
  computed: {
    ...mapGetters(["question", "param", "info"])
  },
  mounted() {
    this.getPaperInfo(this.info.paperId);
    this.getInviteInfo();
  },
  methods: {
    jumpUrl() {
      let tim = (3 + Number((Math.random() * 2).toFixed(2))) * 1000;
      setTimeout(() => {
        //执行跳转操作
        // this.$router.push({
        //   path: "/over"
        // });
      }, tim);
    },
    anaTime() {
      this.anAbtn = !this.anAbtn;
      setInterval(() => {
        this.anAbtn = !this.anAbtn;
      }, 1000);
    },
    startTime() {
      this.tim = setInterval(() => {
        if (this.point.length >= 3) {
          this.point = ".";
        } else {
          this.point += ".";
        }
      }, 800);
    },
    getPaperInfo(id) {
      if (!id) {
        return;
      }
      getPaperInfo(id).then(res => {
        if (res.code == 200) {
          let result = this.analyseTest(res.data.list);

          this.info.data = res.data;
          this.info.data.rightNum = result;
          this.$store.dispatch("setInfo", this.info);
        }
      });
    },

    analyseTest(data) {
      let rightNum = 0;
      data.map(item => {
        if (item.studentAnswer[0].isTrue) {
          rightNum += 1;
        }
      });

      return rightNum;
    },
    getInviteInfo() {
      let oid = this.param.oid;
      let campusId = this.param.campusId;
      let inviterId = this.param.inviterId;
      let type = 1;
      let id = "";
      if (campusId) {
        type = 0;
        id = campusId;
      } else {
        type = 1;
        id = oid;
      }
      getInviteInfo(id, type).then(res => {
        if (res.code == 200) {
          this.info.userInfo = Object.assign({}, this.info.userInfo, res.data);
          this.$store.dispatch("setInfo", this.info);
        }
      });
    }
  }
};
</script>
